#pragma once
#include "PlayerColor.h"

namespace catan
{
	class PlayerFactory
	{
	public:
		PlayerFactory(void);
		~PlayerFactory(void);
		Handle<Player> CreatePlayer(PlayerColor::Enum color, Handle<Board> board);
		//void RecyclePlayer(Handle<Player> player);
	private:
		Handle<PlayerPack> CreatePlayerPack(Handle<Board> board);
		Handle<Player> mPlayer;

		template< class _Ty>
		void RecycleVectors(_Ty& tys);

		template< class _Ty>
		void Recycle(_Ty*& ty);
	};

	template< class _Ty>
	void PlayerFactory::Recycle( _Ty*& ty )
	{
		if (ty)
		{
			delete ty;
			ty = 0;
		}
	}

	template< class _Ty>
	void PlayerFactory::RecycleVectors( _Ty& ty )
	{
		for (typename _Ty::iterator it(ty.begin());
			it != ty.end(); ++it)
		{
			if((*it))
			{
				delete *it;
				*it = 0;
			}
		}
		ty.clear();
	}
}	